﻿
Imports freclust
Imports fcesdiskslice_atom = planet.storageJobConsumerInternal.fcesdiskslice_atom(Of _true)
Imports fcesdiskslice = planet.storageJobConsumerInternal.fcesdiskslice(Of _true)

Namespace storageJobConsumerInternal
    Friend Class fceslite4
        Inherits fceslite4(Of _false)
    End Class

    Public Class diskslice4
        Inherits fcesdiskslice
        Private ReadOnly fces As fceslite4 = Nothing

        Public Sub New()
            fces = New fceslite4()
        End Sub

        Protected Overrides Function meta(ByVal atom As fcesdiskslice_atom, ByVal buff As bytes) As bytes
            Dim cid As Int64 = 0
            assert(fces.allocate(buff.size(), cid))
            atom.clusterId() = cid
            Return convertor.tobytes(cid)
        End Function

        Protected Overrides Function read(ByVal atom As fcesdiskslice_atom,
                                          ByVal result As pointer(Of bytes)) As eventComb
            Return fces.read(atom.clusterId(), result)
        End Function

        Protected Overrides Function sizeof(ByVal atom As fcesdiskslice_atom) As Int64
            Dim size As Int64 = 0
            If fces.sizeof(atom.clusterId(), size) Then
                Return size
            Else
                Return npos
            End If
        End Function

        Protected Overrides Function write(ByVal atom As fcesdiskslice_atom, ByVal buff As bytes) As eventComb
            Return fces.write(atom.clusterId(), buff)
        End Function

        Protected Overrides Function append(ByVal atom As fcesdiskslice_atom, ByVal buff As bytes) As eventComb
            Return fces.append(atom.clusterId(), buff)
        End Function

        Protected Overrides Function modify(ByVal atom As fcesdiskslice_atom, ByVal buff As bytes) As eventComb
            Return write(atom, buff)
        End Function

        Protected Overrides Function delete(ByVal atom As fcesdiskslice_atom) As eventComb
            Return fces.delete(atom.clusterId())
        End Function

        Protected Overrides Function version() As String
            Return "Hzj_jie-Gemini-FreeCluster4"
        End Function

        Protected Overrides Sub flush()
            assert(fces.flush())
        End Sub

        Protected Overrides Function open_fces(ByVal file As String, ByVal buffSize As Int32) As Boolean
            Return fces.open(file, buffSize)
        End Function

        Protected Overrides Function close_fces() As Boolean
            fces.close()
            Return True
        End Function

        Protected Overrides Function fcesfolder() As String
            Return "fces4"
        End Function

        Public Shared Shadows Function initial(ByVal name As String,
                                               ByVal config As configParser,
                                               ByVal c As diskslice4) As Boolean
            Return fcesdiskslice.initial(name, config, convertor.cast(Of fcesdiskslice)(c))
        End Function
    End Class
End Namespace
